package com.felix.thread.staticSync;

/**
 * StaticSyncDemo
 *
 * @author xjh
 * @version 1.0
 * @date 2019-03-21
 */
public class StaticSyncDemo {

    public static void main(String[] args) {
        User user = new User();
        Thread t1 = new Thread(() -> User.staticMethod1());
        Thread t2 = new Thread(() -> User.staticMethod1());
        t1.start();
        t2.start();

    }
}

class User {

    public synchronized void method1() {
        int i = 5;
        while (i-- > 0) {
            System.out.println(Thread.currentThread().getName() + " : " + i);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {

            }
        }
    }

    public static synchronized void staticMethod1() {
        int i = 5;
        while (i-- > 0) {
            System.out.println(Thread.currentThread().getName() + " : " + i);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {

            }
        }
    }
}
